import { parse } from 'workplus-query-string';
import Xhr from './axios/xhr';

export default function login() {
  const query = parse();
  const { ticket, domain_id, org_id, user_id } = query;

  if (!ticket) {
    return Promise.resolve({ logged: true });
  }

  return Xhr.post('/session', {
    ticket,
    userId: user_id,
    orgId: org_id,
    domainId: domain_id,
  });
}
